package com.jw.common;

/**
 * @author: jiangwang
 * @created: 2024/3/4 14:06
 */
public class ResultBean<T> {
    public static final int ERROR = -1;
    public static final int OK = 0;

    /**
     * 返回结果码 0成功,其他都是失败
     */
    private int resultCode = ResultBean.OK;

    /**
     * 操作结果信息
     */
    private String resultMessage = "";

    /**
     * 返回的数据
     */
    private T data;

    public static <T> ResultBean<T> ok() {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(OK);
        return r;
    }

    public static <T> ResultBean<T> ok(String msg) {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(OK);
        r.setResultMessage(msg);
        return r;
    }

    public static <T> ResultBean<T> ok(T data) {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(OK);
        r.setData(data);
        return r;
    }

    public static <T> ResultBean<T> ok(String msg, T data) {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(OK);
        r.setResultMessage(msg);
        r.setData(data);
        return r;
    }

    public static <T> ResultBean<T> error(String msg, T data) {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(ERROR);
        r.setResultMessage(msg);
        r.setData(data);
        return r;
    }

    public static <T> ResultBean<T> error(String msg) {
        return error(ERROR, msg);
    }

    public static <T> ResultBean<T> error(int code, String msg) {
        ResultBean<T> r = new ResultBean<T>();
        r.setResultCode(code);
        r.setResultMessage(msg);
        return r;
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMessage() {
        return resultMessage;
    }

    public void setResultMessage(String resultMessage) {
        this.resultMessage = resultMessage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
